package com.ccom.file.controller;

import com.ccom.core.common.constant.ServiceNameConstants;
import com.ccom.core.common.model.Result;
import com.ccom.starter.file.service.OOSService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author zjj
 * @date 2021/11/1 13:56
 * @description
 */
@Api(tags = "测试file-controller")
@Slf4j
@RestController
@RequestMapping(ServiceNameConstants.FILE_SERVICE_URL_PREFIX + "/test")
public class FileTestController {

    private static final String BASE_PATH = "fileTest/";

    @Autowired
    private OOSService oosService;

    @PostMapping("/uploadToMinio")
    public Result testUploadFile(@RequestBody MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        oosService.uploadFile(BASE_PATH + fileName, file.getInputStream());
        return Result.success();
    }
}
